//地图初始化
var MAP;


MapObj = {
	normalBasemapLayer: null,
	imageBasemapLayer: null,
	// sfqgqLayer:null,
	imageLayer: null,
	landLayer: null,
	planLayer: null,
	terrainLayer: null,
	image201904Layer: null,
	image201903Layer: null,
	image202003Layer: null,
	image202002Layer: null,
	image202001Layer: null,
	imageYD2Layer:null,
	imageYD5Layer:null,
	imageYD8Layer:null,
	imageYD9Layer:null,
	imageYD10Layer:null,
	
	
	landuseQueryUrl:"http://10.108.3.57/server/rest/services/landuse_query/MapServer",
	deepwellUrl: 'http://10.108.3.57/server/rest/services/KeyProject_Point/MapServer',
	deepwellUrl1: 'http://10.108.3.57/server/rest/services/landuse_level2tile2/MapServer',
	deepwellUrl2: 'http://10.108.3.57/server/rest/services/landuse_level2tile2/MapServer',
	// img2019thirdQquarterUrl: 'http://10.108.3.57/server/rest/services/QPDWG/MapServer',
	img2018Url: 'http://10.108.3.57/server/rest/services/image/history_image_2018/MapServer',
	img2017Url: 'http://10.108.3.57/server/rest/services/image/history_image_2017/MapServer',
	img2016Url: 'http://10.108.3.57/server/rest/services/image/history_image_2016/MapServer',
	img2015Url: 'http://10.108.3.57/server/rest/services/image/history_image_2015/MapServer',
	img2014Url: 'http://10.108.3.57/server/rest/services/image/history_image_2014/MapServer',
	img2013Url: 'http://10.108.3.57/server/rest/services/image/history_image_2013/MapServer',
	img2012Url: 'http://10.108.3.57/server/rest/services/image/history_image_2012/MapServer',
	// qingpuUrl:'http://10.108.3.57/server/rest/services/QPDWG/MapServer'

	// 定位的注记所在图层
	locationGrahicLayer: null,
	locationGrahicLayer2: null,

	// 用户当前位置
	currentLat: null,
	currentLon: null,
	init: function() {
		//		var normalm = L.tileLayer.chinaProvider('GaoDe.Normal.Map', {
		//			maxZoom: 18,
		//			minZoom: 5,
		//			detectRetina: false
		//		});
		//		

		//标准的地图
		var normalm = L.esri.tiledMapLayer({
			maxZoom: 5,
			maxZoom: 16,
			// continuousWorld: true,
			// url: 'http://10.108.3.57/server/rest/services/CSJ_BASEMAP_LIGHT/MapServer',
			url:"http://10.108.3.57/server/rest/services/CSJ_BASEMAP_LIGHT/MapServer"
			
			
			// continuousWorld: true,
		})
		// var normalm = L.tileLayer('http://10.108.3.57/server/rest/services/CSJ_BASEMAP_LIGHT/MapServer', {
		// 	maxZoom: 18,
		// 	minZoom: 5,
		// 	detectRetina: false,
			
		// });

		// 2019 四季度影像图
		var image201904Url = L.esri.tiledMapLayer({
			url: 'http://10.108.3.57/server/rest/services/image/sat_image_submeter_20194jd/MapServer',
			maxZoom: 5,
			maxZoom: 16,
			continuousWorld: true,
		})
		// 2019 三季度影像图
		var image201903Url = L.esri.tiledMapLayer({
			url: 'http://10.108.3.57/server/rest/services/image/sat_image_submeter_20193jd/MapServer',
			maxZoom: 5,
			maxZoom: 16,
			continuousWorld: true,
		})
		// 2020 三季度影像图
		var image202003Url = L.esri.tiledMapLayer({
			url: 'http://10.108.3.57/server/rest/services/image/sat_image_submeter_20203jd/MapServer',
			maxZoom: 5,
			maxZoom: 16,
			continuousWorld: true,
		})
		// 2020 二季度影像图
		var image202002Url = L.esri.tiledMapLayer({
			url: 'http://10.108.3.57/server/rest/services/image/sat_image_submeter_20202jd/MapServer',
			maxZoom: 5,
			maxZoom: 16,
			continuousWorld: true,
		})
		// 2020 一季度影像图
		var image202001Url = L.esri.tiledMapLayer({
			url: 'http://10.108.3.57/server/rest/services/image/sat_image_submeter_20201jd/MapServer',
			maxZoom: 5,
			maxZoom: 16,
			continuousWorld: true,
		})

		// Geoq.Normal.Gray Geoq.Normal.Map Geoq.Normal.Warm

		//卫星地图
		var imgm = L.esri.tiledMapLayer({
			maxZoom: 5,
			maxZoom: 16,
			// url: 'http://10.108.3.57/server/rest/services/CSJ_BASEMAP_DARK/MapServer',
			url:'http://10.108.3.57/server/rest/services/image/sat_image_submeter_20202jd/MapServer',
			// url:"http://10.108.3.57/server/rest/services/CSJ_BASEMAP_LIGHT/MapServer"
			continuousWorld: true,
		})



		//影像图
		var SAT_IMAGE_SUBMETER_202002 = L.esri.tiledMapLayer({
			url: 'http://10.108.3.57/server/rest/services/image/sat_image_submeter_20202jd/MapServer',
			continuousWorld: true,
		})

		var SAT_IMAGE_SUBMETER_202002_plus = L.esri.tiledMapLayer({
			url: 'http://10.108.3.57/server/rest/services/image/air_image_20cm/MapServer',
			continuousWorld: true,
		})

		var zhongxintaifu = L.esri.tiledMapLayer({
			url: 'http://10.108.3.57/server/rest/services/zhongxintaifu/MapServer',
			continuousWorld: true,
		})

		var IMAGE_LABEL = L.esri.tiledMapLayer({
			url: 'http://10.108.3.57/server/rest/services/IMAGE_LABEL/MapServer',
			continuousWorld: true,
		})
		// 示范区光圈
		var sfq_gq = L.esri.tiledMapLayer({
			url: 'http://10.108.3.57/server/rest/services/SFQ_MASK2/MapServer',
			continuousWorld: true,
		})

		//三调图
		var LANDUSE_JS = L.esri.tiledMapLayer({
			url: 'http://10.108.3.57/server/rest/services/Hosted/landuse_js_img/MapServer',
			continuousWorld: true,
		})

		var LANDUSE_WJ = L.esri.tiledMapLayer({
			url: 'http://10.108.3.57/server/rest/services/Hosted/landuse_wj_img/MapServer',
			continuousWorld: true,
		})

		var LANDUSE_QP = L.esri.tiledMapLayer({
			url: 'http://10.108.3.57/server/rest/services/Hosted/landuse_qp_img/MapServer',
			continuousWorld: true,
		})

		var landuse_query = L.esri.tiledMapLayer({
			url: 'http://10.108.3.57/server/rest/services/landuse_query/MapServer',
			continuousWorld: true,
		})
		// //规划图
		var LANDPLAN_L0 = L.esri.tiledMapLayer({
			// url: 'http://10.108.3.57/server/rest/services/landuse_class1tile/MapServer',
			url: "http://10.108.3.57/server/rest/services/landuse_class1tile/MapServer"
			// continuousWorld: true,
		})

		var LANDPLAN_L1 = L.esri.tiledMapLayer({
			// url: 'http://10.108.3.57/server/rest/services/landuse_level2tile2/MapServer',
			url: "http://10.108.3.57/server/rest/services/landuse_level2tile2/MapServer"
			// continuousWorld: true,
		})

		var LANDPLAN_L2 = L.esri.tiledMapLayer({
			// url: 'http://10.108.3.57/server/rest/services/farmland/MapServer',
			url: "http://10.108.3.57/server/rest/services/farmland/MapServer"
			// continuousWorld: true,
		})

		//地形图
		var QPDWG = L.esri.tiledMapLayer({
			// url: 'http://10.108.3.57/server/rest/services/QPDWG/MapServer',
			url: "http://10.108.3.57/server/rest/services/QPDWG/MapServer"
			// continuousWorld: true,
		})

		var JSDWG = L.esri.tiledMapLayer({
			// url: 'http://10.108.3.57/server/rest/services/JSDWG/MapServer',
			url: "http://10.108.3.57/server/rest/services/JSDWG/MapServer"
			// continuousWorld: true,
		})

		var WJDWG = L.esri.tiledMapLayer({
			url: 'http://10.108.3.57/server/rest/services/WJDWG/MapServer',
			// continuousWorld: true,
		})
		var DWG_COVER = L.esri.tiledMapLayer({
			// url: 'http://10.108.3.57/server/rest/services/street/MapServer',
			url: "http://10.108.3.57/server/rest/services/street/MapServer"
			// continuousWorld: true,
		})
		// 元荡图层 
		var backgroundImage = L.esri.tiledMapLayer({
			// url: 'http://10.108.3.57/server/rest/services/street/MapServer',
			url: "http://10.108.3.57/server/rest/services/image/air_image_20cm/MapServer"
			// continuousWorld: true,
		})
		var chilonedYD2 = L.esri.tiledMapLayer({
			// url: 'http://10.108.3.57/server/rest/services/street/MapServer',
			url: "http://10.108.3.57/server/rest/services/image/sat_image_submeter_20201jd/MapServer"
			// continuousWorld: true,
		})
		
		
		var chilonedYD5 = L.esri.tiledMapLayer({
			// url: 'http://10.108.3.57/server/rest/services/street/MapServer',
			url: "http://10.108.3.57/server/rest/services/image/sat_image_submeter_20202jd/MapServer"
			// continuousWorld: true,
		})
		var chilonedYD8 = L.esri.tiledMapLayer({
			// url: 'http://10.108.3.57/server/rest/services/street/MapServer',
			url: "http://10.108.3.57/server/rest/services/image/air_image_20cm/MapServer"
			// continuousWorld: true,
		})
		var chilonedYD9 = L.esri.tiledMapLayer({
			// url: 'http://10.108.3.57/server/rest/services/street/MapServer',
			url: "http://10.108.3.57/server/rest/services/image/uav_image_yuandang/MapServer"
			// continuousWorld: true,
		})
		var chilonedYD10 = L.esri.tiledMapLayer({
			// url: 'http://10.108.3.57/server/rest/services/street/MapServer',
			url: "http://10.108.3.57/server/rest/services/image/uav_image_yuandang4/MapServer"
			// continuousWorld: true,
		})
		

		this.image201904Layer = L.layerGroup([image201904Url]);
		this.image201903Layer = L.layerGroup([image201903Url]);
		this.image202003Layer = L.layerGroup([image202003Url]);
		this.image202002Layer = L.layerGroup([image202002Url]);
		this.image202001Layer = L.layerGroup([image202001Url]);


		this.normalBasemapLayer = L.layerGroup([normalm,sfq_gq]);
		this.imageBasemapLayer = L.layerGroup([imgm,sfq_gq]);
		
		this.imageYD2Layer = L.layerGroup([chilonedYD2,backgroundImage]);
		this.imageYD5Layer = L.layerGroup([chilonedYD5,backgroundImage]);
		this.imageYD8Layer = L.layerGroup([chilonedYD8,backgroundImage]);
		this.imageYD9Layer = L.layerGroup([chilonedYD9,backgroundImage]);
		this.imageYD10Layer = L.layerGroup([chilonedYD10,backgroundImage]);
		// this.sfqgqLayer = L.layerGroup([sfq_gq]);


		this.imageLayer = L.layerGroup([SAT_IMAGE_SUBMETER_202002, SAT_IMAGE_SUBMETER_202002_plus, zhongxintaifu,
			IMAGE_LABEL, sfq_gq
		]);
		this.landLayer = L.layerGroup([LANDUSE_JS, LANDUSE_WJ, LANDUSE_QP, landuse_query, sfq_gq]);
		this.planLayer = L.layerGroup([LANDPLAN_L0, LANDPLAN_L1, LANDPLAN_L2, sfq_gq]);
		this.terrainLayer = L.layerGroup([QPDWG, JSDWG, WJDWG, DWG_COVER, sfq_gq]);


		//		var imga = L.tileLayer.chinaProvider('GaoDe.Satellite.Annotion', {
		//			maxZoom: 18,
		//			minZoom: 5
		//		});

		//		this.imageBasemapLayer = L.layerGroup([imgm, imga]);

		//定义图层的数组
		// MAPARR

		MAP = L.map("map", {
			center: [31, 120.9],
			zoom: 8,
			layers: [this.normalBasemapLayer],
			zoomControl: false,
			attributionControl: false,
			intertia: true,
			intertiaDeceleration: 5
		});
	

		this.deepwellLayer = L.esri.dynamicMapLayer({
			url: this.deepwellUrl,
			opacity: 1
		});

		this.landuseQuery = L.esri.dynamicMapLayer({
			url: this.landuseQueryUrl,
			opacity: 1
		});


		// this.deepwellLayer2 = L.esri.dynamicMapLayer({
		// 	url: this.deepwellUrl2,
		// 	opacity: 1
		// });

		// this.img2019thirdQquarterLayer = L.esri.dynamicMapLayer({
		// 	url: this.img2019thirdQquarterUrl,
		// 	opacity: 1
		// });
		this.img2018Layer = L.esri.dynamicMapLayer({
			url: this.img2018Url,
			opacity: 1
		});
		this.img2017Layer = L.esri.dynamicMapLayer({
			url: this.img2017Url,
			opacity: 1
		});
		this.img2016Layer = L.esri.dynamicMapLayer({
			url: this.img2016Url,
			opacity: 1
		});
		this.img2015Layer = L.esri.dynamicMapLayer({
			url: this.img2015Url,
			opacity: 1
		});
		this.img2014Layer = L.esri.dynamicMapLayer({
			url: this.img2014Url,
			opacity: 1
		});
		this.img2013Layer = L.esri.dynamicMapLayer({
			url: this.img2013Url,
			opacity: 1
		});
		this.img2012Layer = L.esri.dynamicMapLayer({
			url: this.img2012Url,
			opacity: 1
		});


		var deepwellIcon = L.icon({
			iconUrl: 'img/deepwell.svg',
			iconSize: [24, 24],
		});

		this.deepwellClusterLayer = L.esri.Cluster.featureLayer({
			url: this.deepwellUrl + '/2',
			polygonOptions: {
				color: "#2d84c8"
			},
			pointToLayer: function(geojson, latlng) {
				return L.marker(latlng, {
					icon: deepwellIcon
				})
			}
		}).addTo(MAP);

		//		this.scopeLayer = L.esri.dynamicMapLayer({
		//			url: this.scopeUrl,
		//			opacity: 1
		//		}).addTo(MAP);
		//		this.propertyLayer = L.esri.dynamicMapLayer({
		//			url: this.propertyUrl,
		//			opacity: 1
		//		})
		//		this.lotGotLayer = L.esri.dynamicMapLayer({
		//			url: this.lotGotUrl,
		//			opacity: 1
		//		})
		//		this.planLayer = L.esri.dynamicMapLayer({
		//			url: this.planUrl,
		//			opacity: 1
		//		})

		mui(".mui-content").on('tap', '.map', function(event) {
			var latlng = MAP.containerPointToLatLng(event.detail.center)
			MAP.fire('click', latlng)
		})
		GMIdentify.beginIdentify();
		GMQuery.init();
	},

	getMap: function() {
		return MAP;
	},
	mapClear: function() {
		GMQuery.clear();
		DrawTool.clear();
	}
}